
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>

<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title">
					<h4>资源编辑&nbsp;<span style="color: black;">（<i class="fa fa-tag"></i>${requestScope.approveStatusMap[requestScope.prodResource.approveStatus]}）</span></h4>
					<div class="ibox-tools">
					</div>
				</div>

				<div class="ibox-content">
					<form id="editForm" action="web/prodResource/editProdResource" method="post">
					
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>资源编码</label>
							<div class="col-sm-10">
								<input id="resourceCode" name="resourceCode" type="text" class="form-control" value="${requestScope.prodResource.resourceCode}">
							</div>
						</div>
						<div class="hr-line-dashed"></div>

						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>资源名称</label>
							<div class="col-sm-10">
								<input id="resourceName" name="resourceName" type="text" class="form-control" value="${requestScope.prodResource.resourceName}">
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>资源类别</label>
							<div class="col-sm-10">
								<select name="resourceType" id="resourceType" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.resourceTypeMap}" var="resourceType">
			                       		<option value="${resourceType.key}">${resourceType.value}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label">资源描述</label>
							<div class="col-sm-10">
								<textarea id="resourceDesc" name="resourceDesc" rows="" cols="" class="form-control">${requestScope.prodResource.resourceDesc}</textarea>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>资源单位</label>
							<div class="col-sm-10">
								<select name="resourceUnit" id="resourceUnit" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.materialUnitMap}" var="materialUnit">
			                       		<option value="${materialUnit.key}">${materialUnit.value}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>计费类型</label>
							<div class="col-sm-10">
								<select name="chargeType" id="chargeType" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.resourceChargeTypeMap}" var="resourceChargeType">
			                       		<option value="${resourceChargeType.key}">${resourceChargeType.value}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>基准类型</label>
							<div class="col-sm-10">
								<select name="countType" id="countType" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.resourceCountTypeMap}" var="resourceCountType">
			                       		<option value="${resourceCountType.key}">${resourceCountType.value}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>计算成本</label>
							<div class="col-sm-10">
								<select name="costFlag" id="costFlag" class="form-control">
									<option value="" selected="">请选择</option>
									<option value="Y">是</option>
									<option value="N">否</option>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>标准成本费率</label>
							<div class="col-sm-10 input-group">
								<input id="costAmount" name="costAmount" type="text" class="form-control" value="${requestScope.prodResource.costAmount}">
								<span class="input-group-addon">元</span>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span>状态</label>
	
	                        <div class="col-sm-10">
	                        <select class="form-control m-b" name="status" id="status">
	                            <option value="Y" selected="selected">有效</option>
	                            <option value="N">无效</option>
	                        </select>
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>

						<div class="form-group row">
							<div class="col-sm-12 col-sm-offset-2 text-right">
								<button class="btn btn-white btn-lg" type="button" onclick="window.location.href='web/prodResource/getProdResourceList'">返回</button>&nbsp;
								<c:if test="${param.resourceId==null||param.resourceId==''||requestScope.prodResource.approveStatus=='UNSUBMIT'||requestScope.prodResource.approveStatus=='REJECT' }">
									<button class="ladda-button ladda-button-demo btn btn-success btn-lg" data-style="expand-right">&nbsp;&nbsp;保存&nbsp;&nbsp;<i class="fa fa-save"></i></button>
								</c:if>
								
								<c:if test="${param.resourceId!=null&&param.resourceId!=''}">
									<c:if test="${requestScope.prodResource.approveStatus=='UNSUBMIT'||requestScope.prodResource.approveStatus=='REJECT' }">
										<button class="btn btn-primary btn-lg" type="button" onclick="window.location.href='web/prodResource/updateApproveStatus?id=${param.resourceId}&approveStatus=SUBMIT'">&nbsp;&nbsp;提交&nbsp;&nbsp;<i class="fa fa-arrow-circle-right"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.prodResource.approveStatus=='SUBMIT' }">
										<button class="btn btn-warning btn-lg btn-redragon-approve" type="button" onclick="approveData()">&nbsp;&nbsp;审核通过&nbsp;&nbsp;<i class="fa fa-check-circle"></i></button>&nbsp;
										<button class="btn btn-danger btn-lg btn-redragon-approve" type="button" onclick="window.location.href='web/prodResource/updateApproveStatus?id=${param.resourceId}&approveStatus=REJECT'">&nbsp;&nbsp;驳回&nbsp;&nbsp;<i class="fa fa-times-circle"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.prodResource.approveStatus=='APPROVE' }">
										<button class="btn btn-success btn-lg" type="button" onclick="alterData()">&nbsp;&nbsp;变更&nbsp;&nbsp;<i class="fa fa-retweet"></i></button>&nbsp;
									</c:if>
								</c:if>
							</div>
						</div>
						
						<input type="hidden" name="resourceId" value="${requestScope.prodResource.resourceId}">
						<input type="hidden" name="createdDate" value="${requestScope.prodResource.createdDate}">
						<input type="hidden" name="createdBy" value="${requestScope.prodResource.createdBy}">
					</form>
				</div>
			</div>
		</div>
	</div>
</div>


<script>
	$(document).ready(function() {
		//初始化status
		if("${requestScope.prodResource.status}"!=""){
			$("#status").val("${requestScope.prodResource.status}");
		}
		//初始化resourceType
		if("${requestScope.prodResource.resourceType}"!=""){
			$("#resourceType").val("${requestScope.prodResource.resourceType}");
		}
		//初始化chargeType
		if("${requestScope.prodResource.chargeType}"!=""){
			$("#chargeType").val("${requestScope.prodResource.chargeType}");
		}
		//初始化countType
		if("${requestScope.prodResource.countType}"!=""){
			$("#countType").val("${requestScope.prodResource.countType}");
		}
		//初始化resourceUnit
		if("${requestScope.prodResource.resourceUnit}"!=""){
			$("#resourceUnit").val("${requestScope.prodResource.resourceUnit}");
		}
		//初始化costFlag
		if("${requestScope.prodResource.costFlag}"!=""){
			$("#costFlag").val("${requestScope.prodResource.costFlag}");
		}
		//初始化code只读
		if("${requestScope.prodResource.resourceId}"!=""){
			$("#resourceCode").prop("readonly", true);
		}
		

		//表单提交	
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#editForm").valid();
			//l.ladda('stop');
		});

		$("#editForm").validate({
			rules : {
				resourceCode : {
					required : true,
					isCode : true,
				},
				resourceName : {
					required : true,
				},
				resourceType : {
					required : true,
				},
				chargeType : {
					required : true,
				},
				countType : {
					required : true,
				},
				resourceUnit : {
					required : true,
				},
				costFlag : {
					required : true,
				},
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
				
				if($("#costFlag").val()=="Y"){
					if($("#costAmount").val()==""||!$.isNumeric($("#costAmount").val())||parseFloat($("#costAmount").val())<0){
						submitFlag = "N";
						redragonJS.alert("请输入有效的成本费用");
					}
				}
				
				//提交
				if(submitFlag=="Y"){
					l.ladda('start');
		        	form.submit();
				}
		    }
		});
	});
	
	//审批通过
	function approveData(){
		redragonJS.confirm("确认审批通过？", function(){
			window.location.href='web/prodResource/updateApproveStatus?id=${param.resourceId}&approveStatus=APPROVE';
		});
	}
	
	//数据变更
	function alterData(){
		redragonJS.confirm("确认变更数据？数据变更可能会影响到已有的业务！", function(){
			window.location.href='web/prodResource/updateApproveStatus?id=${param.resourceId}&approveStatus=UNSUBMIT';
		});
	}
</script>